package com.ubing.gpermission.permission;

import com.ubing.gpermission.permission.aop.PermissionAop;
import com.ubing.gpermission.permission.bean.PermissionSource;
import com.ubing.gpermission.permission.handler.DefaultPermissionHandler;
import com.ubing.gpermission.permission.handler.PermissionHandler;
import com.ubing.gpermission.permission.processor.PermissionBeanFactoryPostProcessor;
import com.ubing.gpermission.permission.runner.PermissionRunner;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class AutoPermissionConfig {

	@Bean
	public PermissionSource permissionSource(){
		return new PermissionSource();
	}


	@Bean
	@ConditionalOnMissingBean(PermissionHandler.class)
	public PermissionHandler permissionHandler(@Autowired PermissionSource permissionSource){
		return new DefaultPermissionHandler(permissionSource);
	}

	@Bean
	public PermissionAop permissionAop(){
		return new PermissionAop();
	}

	@Bean
	public PermissionRunner permissionRunner(){
		return new PermissionRunner();
	}

	@Bean
	public BeanFactoryPostProcessor beanFactoryPostProcessor(){
		return new PermissionBeanFactoryPostProcessor();
	}

}
